//
//  Marco.h
//  Project_Demo
//
//  Created by caoxiaozhu on 2018/6/29.
//  Copyright © 2018年 caoxiaozhu. All rights reserved.
//

#ifndef Macro_h
#define Macro_h

//
#pragma mark - 秘钥
#define PGGkey          @"PGGCRYPTOKEY1024" //key自行修改
#define PGGIv             @"PGGPASSWORD@1024" //偏移量自行修改
#define TkEY                @"WX6SM7K34567w34xs34mk987"
#define TIV                     @"45789432"

//0.屏幕各种高度
#pragma mark - 字体
#define BFONT(a) ([UIFont boldSystemFontOfSize:(a)])
#define FONT(a) ([UIFont systemFontOfSize:(a)])

//1.获取通知中心
#pragma mark - 获取通知中心
#define XZNotificationCenter [NSNotificationCenter defaultCenter]
//发送通知
#define XZPostNotification(name,obj) [[NSNotificationCenter defaultCenter] postNotificationName:name object:obj];

//2.屏幕各种相关
#pragma mark - 屏幕各种相关
#define FRAME(x,y,width,height)  CGRectMake(x, y, width, height)
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
#define TabbarHeight 49*kHeightScale
#define kWidthScale (kscreenWidth / 320.0)
#define kHeightScale (kscreenHeight / 568.0)
#define cellPadding 10*kWidthScale
#define percentageScreenHeight kScreenHeight *1 /8
#define percentageScreenWidth kScreenWidth *1 /8

#define NAV_BAR_HEIGHT        44
#define STATUS_BAR_HEIGHT     20.0
#define TAB_BAR_HEIGHT        49
#define FOOT_BUTTON_HEIGHT    40
#define FOOTVIEW_HEIGHT  60

//判断phoneX
#define KPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)


//3.设置随机颜色
#pragma mark - 设置随机颜色
#define Color_Random [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]

//4.设置RGB颜色/设置RGBA颜色
#pragma mark - 设置RGB颜色/设置RGBA颜色
#define XZRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define XZRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:a]


//5.自定义高效率的 NSLog
#pragma mark - 自定义高效率的 NSLog
#ifdef DEBUG
#define LRLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#else
#define LRLog(...)

#endif


//6.弱引用/强引用
#pragma mark - 弱引用/强引用
#define kWeakSelf(type)  __weak typeof(type) weak##type = type;
#define kStrongSelf(type)  __strong typeof(type) type = weak##type;

//7.设置 view 圆角和边框
#pragma mark - 设置 view 圆角和边框
#define LRViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

//8.由角度转换弧度 由弧度转换角度
#pragma mark - 由角度转换弧度 由弧度转换角度
#define LRDegreesToRadian(x) (M_PI * (x) / 180.0)
#define LRRadianToDegrees(radian) (radian*180.0)/(M_PI)

//9.Window
#pragma mark - Window
#define kWindow [UIApplication sharedApplication].keyWindow

//10.获取图片资源
#pragma mark - 获取图片资源
#define kGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]

//11.获取当前语言
#pragma mark - 获取当前语言
#define LRCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

//12.系统相关信息
#pragma mark - 系统相关信息
//系统版本
#define CurrentSystemVersion [[[UIDevice currentDevice] systemVersion] floatValue]
//当前版本小于某版本
#define IOSAVAILABLEVERSION(version) ([[UIDevice currentDevice] availableVersion:version] < 0)
//获取当前语言
#define CurrentLanguage (［NSLocale preferredLanguages] objectAtIndex:0])

//13.判断是真机还是模拟器
#pragma mark - 判断是真机还是模拟器
#if TARGET_OS_IPHONE
//iPhone Device
#endif

#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif

//14.沙盒目录文件
#pragma mark - 沙盒目录文件
//获取temp
#define kPathTemp NSTemporaryDirectory()

//获取沙盒 Document
#define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]

//获取沙盒 Cache
#define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]


//17.GCD 的宏定义
#pragma mark - GCD 的宏定义
//GCD - 一次性执行
#define kDISPATCH_ONCE_BLOCK(onceBlock) static dispatch_once_t onceToken; dispatch_once(&onceToken, onceBlock);

//GCD - 在Main线程上运行
#define kDISPATCH_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock);

//GCD - 开启异步线程
#define kDISPATCH_GLOBAL_QUEUE_DEFAULT(globalQueueBlock) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlocl);

//18.拨打电话
#pragma mark - 拨打电话
#define canTel                 ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:"]])
#define tel(phoneNumber)       ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNumber]]])
#define telprompt(phoneNumber) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",phoneNumber]]])

//19.打开URL
#pragma mark - 打开URL
#define canOpenURL(appScheme) ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:appScheme]])
#define openURL(appScheme) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:appScheme]])

//20.bundle
#pragma mark - bundle
#define bundleFileName(fileName) [[NSBundle mainBundle] pathForResource:fileName ofType:nil]

//21.常用颜色
#pragma mark - 常用颜色

#define Color_White        [UIColor whiteColor]
#define Color_Line_Color [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1]
#define Color_Black        [UIColor blackColor]
#define Color_Gray         [UIColor grayColor]
#define Color_LightGray    [UIColor grayColor]
#define Color_Gray_Light   [UIColor lightGrayColor]
#define Color_Gray_Dark    [UIColor darkGrayColor]
#define Color_Red          [UIColor redColor]
#define Color_Yellow       [UIColor yellowColor]
#define Color_Green        [UIColor greenColor]
#define Color_Blue         [UIColor blueColor]
#define Color_Clear        [UIColor clearColor]
//UI颜色控制
#define kUIToneBackgroundColor UIColorFromHex(0x807cff) //UI整体背景色调 与文字颜色一一对应
#define kUIToneTextColor UIColorFromHex(0xffffff) //UI整体文字色调 与背景颜色对应
#define kStatusBarStyle UIStatusBarStyleLightContent //状态栏样式
#define kViewBackgroundColor UIColorFromHex(0xf5f5f5) //界面View背景颜色
//colorHEX
#define UIColorFromHexA(hexValue, a)     [UIColor colorWithRed:(((hexValue & 0xFF0000) >> 16))/255.0f green:(((hexValue & 0xFF00) >> 8))/255.0f blue:((hexValue & 0xFF))/255.0f alpha:a]
#define UIColorFromHex(hexValue)        UIColorFromHexA(hexValue, 1.0f)

//22.单例一个类
#pragma mark - 单例一个类
#define SINGLETON_FOR_HEADER(className) \
\
+ (className *)shared##className;

#define SINGLETON_FOR_CLASS(className) \
\
+ (className *)shared##className { \
static className *shared##className = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
shared##className = [[self alloc] init]; \
}); \
return shared##className; \
}

//23.打印当前方法名
#pragma mark - 打印当前方法名
#define ITTDPRINTMETHODNAME() ITTDPRINT(@"%s", __PRETTY_FUNCTION__)

//24.拼接字符串
#pragma mark - 拼接字符串
#define NSStringFormat(format,...) [NSString stringWithFormat:format,##__VA_ARGS__]

//25. View 圆角
#pragma mark - View 圆角
#define ViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]

//View 圆角和加边框
#define ViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

//26.获取系统对象
#pragma mark - 获取系统对象
#define kApplication        [UIApplication sharedApplication]
#define kAppWindow          [UIApplication sharedApplication].delegate.window
#define kAppDelegate        [AppDelegate shareAppDelegate]
#define kRootViewController [UIApplication sharedApplication].delegate.window.rootViewController
#define kUserDefaults       [NSUserDefaults standardUserDefaults]
#define kNotificationCenter [NSNotificationCenter defaultCenter]

//27.数据验证
#pragma mark - 数据验证
#define StrValid(f) (f!=nil && [f isKindOfClass:[NSString class]] && ![f isEqualToString:@""])
#define SafeStr(f) (StrValid(f) ? f:@"")
#define HasString(str,eky) ([str rangeOfString:key].location!=NSNotFound)

#define ValidStr(f) StrValid(f)
#define ValidDict(f) (f!=nil && [f isKindOfClass:[NSDictionary class]])
#define ValidArray(f) (f!=nil && [f isKindOfClass:[NSArray class]] && [f count]>0)
#define ValidNum(f) (f!=nil && [f isKindOfClass:[NSNumber class]])
#define ValidClass(f,cls) (f!=nil && [f isKindOfClass:[cls class]])
#define ValidData(f) (f!=nil && [f isKindOfClass:[NSData class]])

//28.判断是否是X和X的安全区
#pragma mark - 判断是否是X和X的安全区
/** iPhone X 安全区 导航栏 高度*/
#define SafeAreaTopHeight (screenHeight == 812.0 ? 88 : 64)
/** iPhone X 安全区 底部 高度*/
#define SafeAreaBottomHeight (screenHeight == 812.0 ? 34 : 0)
/** 是否是 iPhone X */
#define IS_IPHONEX (screenHeight == 812.0 ? YES : NO)
#define IS_iPhone6_Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1125, 2001), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size)) : NO)

#define IS_iPhone_6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size)) : NO)

#define IS_iPhone_5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)


//29.第三方的单例
#pragma mark - 第三方的单例
#define IQ_KeyboardManager [IQKeyboardManager sharedManager]

#endif /* Marco_h */
